package com.marry.mybatis.redis.controller;

import com.marry.mybatis.redis.mapper.ProductMapper;
import com.marry.mybatis.redis.model.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductMapper productMapper;

    @GetMapping("/{id}")
    public Product getProductInfo(@PathVariable("id") Long productId){
        System.out.println(productId);
        return productMapper.select(productId);

    }

    @PutMapping("/{id}")
    public String updateProductInfo(@PathVariable("id") Long productId,
                                     @RequestBody Product product){
        System.out.println("接受的参数 "+productId+"  | "+product);
        Product oldproduct=productMapper.select(productId);
        oldproduct.setPrice(product.getPrice());
        oldproduct.setName(product.getName());
        productMapper.update(oldproduct);

        return "Success";

    }
}
